<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    


    <script>
        var arr = [{name:'张三',age:10},{name:'李四',age:20}]

        const headers = {
            '姓名':'name',
            '年龄':'age'
        }

        const list = Object.keys(headers)

        console.log(list); // ['姓名','年龄']

        function formatJSON(headers, arr){
            return arr.map(item =>{
                // console.log(item); // {name:'张三',age:10}  {name:'李四',age:20}
                return list.map(key =>{
                    // console.log(key); // 姓名 年龄 姓名 年龄
                    // 返回key所对应的值
                  return  item[headers[key]]
                })
            })
        }

        const result = formatJSON(headers, arr)
        console.log(result); // [[张三,10],[李四,20]]

    </script>
</body>
</html>